<template>
    <el-dialog title="添加退货原因" v-model="props.visible" :before-close="beforeClose" width="30%">
        <el-form :model="ownForm" label-width="100px">
            <el-form-item label="原因类型">
                <el-input v-model="ownForm.name"></el-input>
            </el-form-item>
            <el-form-item label="排序">
                <el-input v-model="ownForm.sort"></el-input>
            </el-form-item>
            <el-form-item label="是否启用">
                <el-switch :value="ownForm.status === 1 ? true : false" @click="changeStatus" />
            </el-form-item>
        </el-form>
        <template #footer>
            <span>
                <el-button @click="closeEdit">取消</el-button>
                <el-button type="primary" @click="onConfirm">确定</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { defineProps, watch, ref, withDefaults, defineEmits } from 'vue'
import type { Ref } from 'vue'
import type { IAddReturnGoods } from '../../../json/request/QmsAdminConreiller/index'

let props = withDefaults(
    defineProps<{
        visible: boolean;
        form: IAddReturnGoods
    }>(), {
    visible: true
})

let ownForm = ref({}) as Ref<IAddReturnGoods>
let nullFrom = ref({}) as Ref<IAddReturnGoods>

let emits = defineEmits<{
    (event: "closeEdit"): void;
    (event: "onConfirmDialog", row: IAddReturnGoods): void;
}>()
let beforeClose = () => {
    emits("closeEdit")

}

watch(() => props.form, (newVal) => {
    // console.log(newVal);
    ownForm.value = { ...newVal }
    nullFrom.value = { ...newVal }
})

let closeEdit = () => {
    ownForm.value = { ...nullFrom.value }
    emits("closeEdit")
}
let changeStatus = () => {
    ownForm.value.status = ownForm.value.status == 1 ? 0 : 1
}

let onConfirm = () => {
    emits("onConfirmDialog", ownForm.value)

}



</script>

<style scoped></style>